package com.dhl.inversion.improve;

/**
 * @title: Inversion
 * @Author danghailiang
 * @Date: 2022/7/25 10:42
 * @Version 1.0
 */
public class InversionImprove {
    public static void main(String[] args) {
        new Person(new Email()).receive();
        new Person(new QQ()).receive();
        new Person(new VX()).receive();
    }
}

/**
 * 1.不利于扩展
 * 2.若发送qq，vx等信息的时候就需要进行对Person进行修改
 * 3.添加一个接口，使得Person类对接口形成依赖。email和vx以及qq实现该接口即可
 * 4.EMAIL,VX,QQ都符合接受的范围，所有符合依赖倒置原则
 */
class Person{
    private IReceive iReceive;

    public Person(IReceive iReceive) {
        this.iReceive = iReceive;
    }

    public void  receive(){
        iReceive.receive();
    }
}
interface IReceive{
    void receive();
}

class Email implements IReceive{
    @Override
    public void receive() {
        System.out.println("发送了邮件");
    }
}
class VX implements IReceive{
    @Override
    public void receive() {
        System.out.println("发送了微信信息");
    }
}
class QQ implements IReceive{
    @Override
    public void receive() {
        System.out.println("发送了QQ信息");
    }
}